package com.infocollect.project.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.infocollect.project.api.entity.TappOrganEntity;
import com.infocollect.project.api.mapper.TappOrganMapper;
import com.infocollect.project.api.service.ITappOrganService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (TappOrgan)表服务实现类
 *
 * @author makejava
 * @since 2019-12-25 10:32:29
 */
@Service("tappOrganService")
public class TappOrganServiceImpl extends ServiceImpl<TappOrganMapper, TappOrganEntity> implements ITappOrganService {


    /**
     * 通过ID查询单条数据
     *
     * @param fid 主键
     * @return 实例对象
     */
    @Override
    public TappOrganEntity queryById(Long fid) {
        return this.baseMapper.selectById(fid);
    }


    /**
     * 查询多条数据
     * @menu 根据实体对象是否有值 进行查询
     * @return 对象列表
     */
    @Override
    public List<TappOrganEntity> queryAll(TappOrganEntity organ){
        return this.baseMapper.queryAll(organ);
    }
    /**
     * 新增数据
     *
     * @param tappOrgan 实例对象
     * @return 实例对象
     */
    @Override
    public TappOrganEntity insert(TappOrganEntity tappOrgan) {
        this.baseMapper.insert(tappOrgan);
        return tappOrgan;
    }

    /**
     * 修改数据
     *
     * @param tappOrgan 实例对象
     * @return 实例对象
     */
    @Override
    public TappOrganEntity update(TappOrganEntity tappOrgan) {
        this.baseMapper.updateById(tappOrgan);
        return this.queryById(tappOrgan.getFid());
    }

    /**
     * 通过主键删除数据
     *
     * @param fid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long fid) {
        return this.baseMapper.deleteById(fid) > 0;
    }

    /**
     *
     * @param code
     * @return
     */
    @Override
    public TappOrganEntity queryByCode(String code){
        QueryWrapper<TappOrganEntity> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("FOrganCode",code);
        return this.baseMapper.selectOne(queryWrapper);

    }

    /**
     *
     * @param fparentid
     * @return
     */
    @Override
    public List<TappOrganEntity> queryByParentID(Long fparentid){
        QueryWrapper<TappOrganEntity> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("fparentid",fparentid);
        return this.baseMapper.selectList(queryWrapper);
    }

    /**
     * 根据机构名称和code查询
     * @param workkey
     * @return
     */
    @Override
   public List<TappOrganEntity> queryNameOrCode(String workkey){
        return this.baseMapper.queryNameOrCode(workkey);
    }
}